package com.lynnyuan.hudi.examples.write;

import org.apache.hudi.common.model.HoodieTableType;
import org.apache.hudi.configuration.FlinkOptions;
import org.apache.hudi.util.HoodiePipeline;

import java.util.HashMap;
import java.util.Map;
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class UpsertWriterDemo {

    public static void main(String[] args) {
        String basePath = "";
        String targetTable = "";

        Map<String, String> options = new HashMap<>();
        options.put(FlinkOptions.PATH.key(), basePath);
        options.put(FlinkOptions.TABLE_TYPE.key(), HoodieTableType.MERGE_ON_READ.name());
        options.put(FlinkOptions.PRECOMBINE_FIELD.key(), "ts");
        // 为了更方便观察源码过程，这里将Bucket的缓存大小设置为0.5kb
        options.put(FlinkOptions.WRITE_BATCH_SIZE.key(), "0.0005");
        // 为了更方便观察源码过程，这里将完整流程中各任务的并行度设置为1
        options.put(FlinkOptions.INDEX_BOOTSTRAP_TASKS.key(), "1");
        options.put(FlinkOptions.BUCKET_ASSIGN_TASKS.key(), "1");
        options.put(FlinkOptions.WRITE_TASKS.key(), "1");
        options.put(FlinkOptions.COMPACTION_TASKS.key(), "1");
        // 为了更方便观察源码过程，将compact的触发机制设置为间隔2次delta_commit
        options.put(FlinkOptions.COMPACTION_TRIGGER_STRATEGY.key(), FlinkOptions.NUM_COMMITS);
        options.put(FlinkOptions.COMPACTION_DELTA_COMMITS.key(), "2");

        HoodiePipeline.Builder builder = HoodiePipeline.builder(targetTable)
                .column("uuid VARCHAR(20)")
                .column("name VARCHAR(10)")
                .column("age INT")
                .column("ts INT")
                .column("`partition` VARCHAR(20)")
                .pk("uuid")
                .partition("partition")
                .options(options);

//        builder.sink(dataStream, false);

//        env.execute("HudiUpsertWriterDemoWithFlink");
    }
}
